package com.example.springboot.redis.controller;

import com.example.springboot.redis.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @desc
 * @Author wangsh
 * @date 2018/6/4 21:47
 */
@RestController
@RequestMapping("/redis")
public class RedisController {

	@Autowired
	private RedisTemplate redisTemplate;

	@RequestMapping("/hello")
	public User hello() throws Exception {

		// 保存对象
		User user = new User("1", "tom1", "123", 10);
		redisTemplate.opsForValue().set(user.getUserName(), user);

		User user2 = (User) redisTemplate.opsForValue().get("tom1");
		System.out.println("user2: " + user2.toString());

		return user2;
	}

}
